// hello2.cpp
/////////////////////////////////////////////////////////


#include <aced.h>
#include <rxregsvc.h>
#include "HloClass.h"

// entry point for this application
extern "C" AcRx::AppRetCode acrxEntryPoint( AcRx::AppMsgCode msg, void* );

// helper functions
void initApp  (void);
void unloadApp(void);

// user defined functions
void hello(void);

/////////////////////////////////////////////////////////////////////
// acrxEntryPoint(internal)
// This function is the entry point for your application.
/////////////////////////////////////////////////////////////////////
AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void* ptr)
{
	switch (msg) {
		case AcRx::kInitAppMsg :
			acrxUnlockApplication(ptr);
			acrxRegisterAppMDIAware(ptr);
			initApp();
		break;

		case AcRx::kUnloadAppMsg :
			unloadApp();
		break;

		case AcRx::kLoadDwgMsg :
			acutPrintf("Received Acrx::kLoadDwgMsg\n");
		break;

		case AcRx::kUnloadDwgMsg :
		break;

		default:
		break;
	} // switch

  return AcRx::kRetOK;
}

void initApp(void)
{
	// TODO: init your application
    // register a command with the AutoCAD command mechanism

	// Step 1:
    //
    //  Add classes to the runtime-identifiable class hierarchy.
    //
    //  This call was defined by use of the ACRX_CONS_DEFINE_MEMBERS()
    //  macro on CHelloClass.

    CHelloClass::rxInit();

	//  If there are any other classes that need to be initialized
	//  they would go here in the following format.
	//  <Classname>::rxInit();

    // Step 2:
    //
    //   Build class relationships before proceeding.  Use after
    //   making a set of <Classname>::rxInit() calls which add a
    //   contiguous growth onto the inheritance tree.
    //
    acrxBuildClassHierarchy();

    // Step 3:
    //
    //   Do any other initialization you need.  The point is that it is
    //   best to do the classes first, since the rest of the initialization
    //   is usually concerned with them.
    //
    //   This example application registers a service name, needed for
    //   symbolic function export,  and a handy object for verifying the
    //   presence of this application.
    //
    acrxRegisterService(SERVICE);

    // register a command with the AutoCAD command mechanism
    //

    acedRegCmds->addCommand("HELLOWORLD_COMMANDS", "HELLO2", "HELLO2",
                    ACRX_CMD_MODAL, hello);

	acutPrintf("Type \"HELLO2\" to execute.\n");
	
}

void unloadApp(void)
{
	// TODO: clean up your application

    // Remove the service that was registered via acrxRegisterService()
    //
    delete acrxServiceDictionary->remove(SERVICE);
    
    // Remove the command group added via acedRegCmds->addCommand
    //
    acedRegCmds->removeGroup("HELLOWORLD_COMMANDS");

    // remove CHelloClass from the AcRx runtime tree
    //
    deleteAcRxClass(CHelloClass::desc());

}

// TODO: add your other functions here
void hello(void)
{
    CHelloClass *pHloClass = new CHelloClass;
    acutPrintf("Calling the CHelloClass hello function:\n");
    if(!pHloClass) {
        acutPrintf("OOPS!! we got a null pointer ...\n");
        return;
    }
    pHloClass->hello();
    delete pHloClass;
    acutPrintf("Deleted the CHelloClass Object pointer.\n");
}